<?php
	include "../controller/ConectBanco.php";
    include "../controller/Sessao.php";
	if($_SESSION["login"] != "admin"){
		header("location:../view/Principal.php");
	}
	
	$idDevice = $_GET['idDevice'];
	
	$queryDevice = mysql_query("SELECT idDevice,idApn,idModel,idDriver,imei,nome,operadora,modelo,idSimCard,numero FROM device
															  NATURAL LEFT JOIN driver
															  NATURAL LEFT JOIN apn
															  NATURAL LEFT JOIN model
															  NATURAL LEFT JOIN simcard	
															  WHERE idDevice = $idDevice")or die(mysql_error());
	$arrayDevice = mysql_fetch_array($queryDevice);
?>	

<!DOCTYPE html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6 lt8"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="no-js ie7 lt8"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="no-js ie8 lt8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="UTF-8" />
        <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">  -->
        <title>Editar Device</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
        <meta name="description" content="Login and Registration Form with HTML5 and CSS3" />
        <meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" />
        <meta name="author" content="Codrops" />
        <link rel="shortcut icon" href="../favicon.ico"> 
        <link rel="stylesheet" type="text/css" href="../css/demo.css" />
        <link rel="stylesheet" type="text/css" href="../css/style.css" />
		
    </head>
    <body>
        <div class="container">
			<?php
				include "MenuAdmin.php";
				Menu::data();
				Menu::menuAdmin(); 
			?>
            <header>
                <h1>LOCALIZAGORA<span></br>Sistema de rastreamento via satelite </span></h1>
				
            </header>
            <section>				
                <div id="container_demo" >
                    <!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4  -->
                    <div id="wrapper">
                        <div id="login" class="animate form">
                            <form  action="../controller/Editar.php?idDevice=<?php echo $idDevice;?>" method="post" autocomplete="on" > 
                                <h1>Editar Device</h1> 
                                 <p> 
                                    <label for="apn" class="apn"  > APN </label>
                                    <select name="idapn" >
										<option></option>
										<?php 
											$query = mysql_query("SELECT * FROM apn ");
											while($array = mysql_fetch_array($query)){
												if($arrayDevice['idApn'] == $array['idApn']){
													echo "<option value=\"".$array['idApn']."\" selected >". $array['operadora'] ."</option>";
												}else{
													echo "<option value=\"".$array['idApn']."\" >". $array['operadora'] ."</option>";
												}
											}
										?>
									</select>
                                </p>
                                 <p> 
                                    <label for="simcard" class="simcard"  > Sim Card </label>
                                    <select name="simcard" >
										<option></option>
										<?php 
											$query = mysql_query("SELECT idSimCard,numero FROM simcard  ");
											while($array = mysql_fetch_array($query)){
												if($arrayDevice['idSimCard'] == $array['idSimCard']){
													echo "<option value=\"".$array['idSimCard']."\" selected >". $array['numero'] ."</option>";
												}else{
													echo "<option value=\"".$array['idSimCard']."\" >". $array['numero'] ."</option>";
												}
											}
										?>
									</select>
                                </p>
                                <p> 
									<label for="model" class="model"  > Model </label>
                                    <select name="idmodel" >
										<option ></option>
										<?php 
											$query = mysql_query("SELECT idModel,modelo FROM model");
											while($array = mysql_fetch_array($query)){
												if($arrayDevice['idModel'] == $array['idModel']){
													echo "<option value=\"".$array['idModel']."\" selected >". $array['modelo'] ."</option>";
												}else{
													echo "<option value=\"".$array['idModel']."\" >". $array['modelo'] ."</option>";
												}
											}
										?>
									</select> 
                                </p>
								<p>
									<label for="driver" class="driver"  > Driver </label>
									<select name="iddriver" >
										<option></option>
										<?php 
											$query = mysql_query("SELECT idDriver,nome FROM driver");
											while($array = mysql_fetch_array($query)){
												if($arrayDevice['idDriver'] == $array['idDriver']){
													echo "<option value=\"".$array['idDriver']."\" selected >". $array['nome'] ."</option>";
												}else{
													echo "<option value=\"".$array['idDriver']."\" >". $array['nome'] ."</option>";
												}
											}
										?>
									</select> 
								</p>
								<p>
									<label for="imei" class="model"  > IMEI </label>
									<input id="imei" name="imei" required="required" value="<?php echo $arrayDevice['imei'];?>" type="text" placeholder="imei"/>
								</p>
								
                               <br><br>
                                <p class="button"> 
                                    <input type="submit" value="Salva" /> 
								</p>
                            </form>
                        </div>

                        
						
                    </div>
                </div>  
            </section>
        </div>
    </body>
</html>